<template>
  <div class="app-container">
    <el-row>
      <el-col :span="24">
        <div class="h_top">
          <div class="bread_title">
            <span>登记出库</span>
          </div>
          <div class="save_button">
            <div class="buttonBox">
              <el-button type="primary" icon="el-icon-back" size="mini" @click="goBack">返回</el-button>
            </div>
            <div class="buttonBox">
              <el-button type="primary" icon="el-icon-document-checked" size="mini" @click="save">保存</el-button>
            </div>
          </div>
        </div>
      </el-col>
    </el-row>
    <div>
      <el-row>
        <el-form ref="form" :model="data" inline :rules="formRules">
          <el-row :gutter="10">
            <el-col :xl="3" :lg="4" :md="5" :sm="6">
              <el-form-item prop="coding">
                <div>编号</div>
                <el-input v-model="data.coding" size="mini" />
              </el-form-item>
            </el-col>
            <el-col :xl="3" :lg="4" :md="5" :sm="6">
              <el-form-item prop="name">
                <div>名称</div>
                <el-input v-model="data.name" size="mini" />
              </el-form-item>
            </el-col>
            <el-col :xl="3" :lg="4" :md="5" :sm="6">
              <el-form-item prop="status">
                <div>状态</div>
                <el-select v-model="data.status" size="mini" disabled>
                  <el-option v-for="(item, index) in appearStatus" :key="index" :value="index" :label="item" />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :xl="3" :lg="4" :md="5" :sm="6">
              <el-form-item prop="apply_admin">
                <div>领用人</div>
                <el-input v-model="data.apply_admin" size="mini" />
              </el-form-item>
            </el-col>
            <el-col :xl="3" :lg="4" :md="5" :sm="6">
              <el-form-item prop="apply_class">
                <div>领用班组</div>
                <el-input v-model="data.apply_class" size="mini" />
              </el-form-item>
            </el-col>
            <el-col :xl="3" :lg="4" :md="5" :sm="6">
              <el-form-item prop="workshop_id">
                <div>领用车间</div>
                <el-select v-model="data.workshop_id" size="mini">
                  <el-option v-for="(item, index) in toolAppearWorkshop" :key="index" :value="index" :label="item" />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :xl="3" :lg="4" :md="5" :sm="6">
              <el-form-item prop="store_id">
                <div>仓库</div>
                <v-select v-model="data.store_id" action="storeList" size="mini" :query="{kind:1}" />
              </el-form-item>
            </el-col>
            <el-col :xl="3" :lg="4" :md="5" :sm="6">
              <el-form-item prop="appear_date">
                <div>出库时间</div>
                <el-date-picker v-model="data.appear_date" type="datetime" placeholder="选择日期" align="right" size="mini" value-format="yyyy-MM-dd HH:mm:ss" />
              </el-form-item>
            </el-col>
            <el-col :xl="3" :lg="4" :md="5" :sm="6">
              <el-form-item prop="admin_id">
                <div>工具库管</div>
                <v-select v-model="data.admin_id" size="mini" :query="{jobs:'116,117,118'}" />
              </el-form-item>
            </el-col>
            <el-col :xl="3" :lg="4" :md="5" :sm="6">
              <el-form-item prop="kind">
                <div>类型</div>
                <el-select v-model="data.kind" size="mini">
                  <el-option v-for="(item, index) in toolAppearKind" :key="index" :value="index" :label="item" />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :xl="3" :lg="4" :md="5" :sm="6">
              <el-form-item prop="sort">
                <div>排序</div>
                <el-input v-model="data.sort" size="mini" />
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <el-tabs>
          <el-tab-pane label="描述">
            <el-row>
              <el-col :span="24">
                <Tinymce id="content" v-model="data.content" />
              </el-col>
            </el-row>
          </el-tab-pane>
        </el-tabs>
      </el-row>
    </div>
  </div>
</template>

<script>
import API from '@/api/tool/appear'
import { appearStatus, toolAppearWorkshop, toolAppearKind } from '@/utils/options'
import VSelect from '@/components/select'
import Tinymce from '@/components/Tinymce/index'
export default {
  inject: ['addOne', 'goUrl'],
  components: {
    VSelect,
    Tinymce
  },
  data() {
    return {
      data: {
        coding: '',
        name: '',
        status: 0,
        sort: 100
      },
      appearStatus,
      toolAppearWorkshop,
      toolAppearKind,
      formRules: {
        coding: [
          {
            required: true,
            message: '请输入编号',
            trigger: 'blur'
          }
        ],
        name: [
          {
            required: true,
            message: '请输入出库单名称',
            trigger: 'blur'
          }
        ],
        status: [
          {
            required: true,
            message: '请选择状态',
            trigger: 'change'
          }
        ],
        apply_admin: [
          {
            required: true,
            message: '请填写领用人',
            trigger: 'blur'
          }
        ],
        apply_class: [
          {
            required: true,
            message: '请填写领用班组',
            trigger: 'blur'
          }
        ],
        workshop_id: [
          {
            required: true,
            message: '请选择申请车间',
            trigger: 'change'
          }
        ],
        appear_date: [
          {
            required: true,
            message: '请输入出库时间',
            trigger: 'blur'
          }
        ],
        admin_id: [
          {
            required: true,
            message: '请选择负责人',
            trigger: 'change'
          }
        ],
        sort: [
          {
            required: true,
            message: '请输入排序',
            trigger: 'blur'
          }
        ],
        kind: [
          {
            required: true,
            message: '请选择种类',
            trigger: 'change'
          }
        ]
      }
    }
  },
  created() {
  },
  methods: {
    save() {
      const thisData = this.data
      const thisForm = this.$refs.form
      this.addOne(API, thisData, thisForm)
    },
    goBack() {
      this.goUrl('/tool/appear')
    }
  }
}
</script>
